local zhiji = fk.CreateSkill {

  name = "joy__zhiji",

  tags = { Skill.Wake, },

}



zhiji:addEffect(fk.TurnStart, {
  name = "joy__zhiji",
  frequency = Skill.Wake,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhiji.name) and
      player:usedSkillTimes(zhiji.name, Player.HistoryGame) == 0 
  end,
  can_wake = function(self, event, target, player, data)
    return player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.general == "joy__jiangwei" then 
    room:notifySkillInvoked(player, "joy__zhiji","drawcard")
      room:changeHero(player,"joy_skin__jiangwei",false,false,true,false)
    elseif player.deputyGeneral == "joy__jiangwei" then
    room:notifySkillInvoked(player, "joy__zhiji","drawcard")
      room:changeHero(player,"joy_skin__jiangwei",false,true,true,false)
    end
    local choices = {"draw2"}
    if player:isWounded() then
      table.insert(choices, "recover")
    end
    local choice = room:askForChoice(player, choices, zhiji.name)
    if choice == "draw2" then
      player:drawCards(2, zhiji.name)
    else
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = zhiji.name
      })
    end
    room:changeMaxHp(player, -1)
    room:handleAddLoseSkills(player, "joy__guanxing", nil, true, false)
  end,
})

return zhiji